//时间5天后的倒计时  getTime 为毫秒数
//2020-10-1 08:00
let date = new Date(2020, 9, 1, 8);
let today = new Date();
let seconds = parseInt((date.getTime() - today.getTime()) / 1000)

//多少天
function countDown(times) {
    //递归边界
    if (times <= 0) {
        return;
    }
    let d = parseInt(times / 86400) //算出天数
    let h = parseInt((times - d * 86400) / 3600) //算出小时
    h = (h + '').padStart(2, '0');
    let m = parseInt((times - d * 86400 - h * 3600) / 60) //算出分钟
    m = (m + '').padStart(2, '0');
    let s = times - d * 86400 - h * 3600 - m * 60  //秒数
    s = (s + '').padStart(2, '0');
    let str = d + '天' + h + ':' + m + ':' + s
    console.log(str);
    //向id=app元素中，写入html内容
    app.innerHTML = str;
    //递归调用，1s后执行一次
    setTimeout(function () {
        times--;
        countDown(times)
    }, 1000)
}
countDown(seconds);
